<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>


    <style type="text/css">
        .search_input {
            overflow: visible;
            background-color: #FFFFFF;
            background-image: none;
            border: 1px solid #e5e6e7;
            border-radius: 1px;
            color: inherit;
            display: block;
            padding: 6px 12px;
            transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
        }
    </style>
</head>

<body>


<div class="breadcome-area">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="breadcome-list single-page-breadcome">
                    <div class="row">
                        <form id="searchForm">
                            <div class="col-lg-2 col-md-2 col-sm-2">

                                <select class="search-int form-control" style="width: 100%;" name="jobId" id="jobId2"
                                        placeholder="请输入电话"></select>

                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2">
                                <select class="search-int form-control" style="width: 100%;" name="departmentId"
                                        id="departmentId2" placeholder="请输入部门"></select>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 ">

                                <input type="text" name="name" class="form-control" placeholder="请输入姓名">

                            </div>

                        </form>
                        <div class="col-lg-2 col-md-2 col-sm-2">
                            <button class="btn btn-primary" onclick="operation.searchForm()">查询</button>
                            <!--
                                                                        <a href="javascript:void(0)" onclick="operation.searchForm()"><i class="fa fa-search"></i></a>
                            -->
                        </div>


                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="mg-b-15">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="product-status-wrap drp-lst">
                    <h4账号管理
                    </h4>
                    <div class="add-product">
                        <a href="#" onclick="operation.addWindow()">添加</a>
                    </div>
                    <div class="asset-inner">

                        <table id="dg"></table>


                    </div>


                </div>
            </div>
        </div>
    </div>
</div>


<!-- 第一个model 开始 -->
<div id="setFormModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static" data-keybord="false">
    <div class="modal-dialog" style="max-width:700px">
        <div class="modal-content">
            <div class="modal-header">
                编辑
            </div>
            <!-- modal-body 开始 -->
            <div class="modal-body">
                <form id="setFormId" class="form-horizontal" enctype="multipart/form-data">
                    <input type="hidden" name="id">

                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="username">账号</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="username" placeholder="请输入账号"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="password">密码</label>
                        <div class="col-sm-6">
                            <input class="form-control" type="password" name="password" value="123456"
                                   placeholder="默认密码：123456"/>
                        </div>
                        <label class="col-sm-2 text-center" style="font-size: 12px"></label>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="name">姓名</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="name" placeholder="请输入姓名"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="phone">电话</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="phone" placeholder="请输入电话"/>
                        </div>
                    </div>


                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="phone">岗位</label>
                        <div class="col-sm-6">

                            <select class="form-control" name="jobId" id="jobId" placeholder="请输入电话"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="phone">部门</label>
                        <div class="col-sm-6">

                            <select class="form-control" name="departmentId" id="departmentId"
                                    placeholder="请输入部门"></select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="phone">邮箱</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="email" placeholder="请输入邮箱"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="lianxirenxingming">联系人姓名</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="lianxirenxingming" placeholder="请输入联系人姓名"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="lianxirenguanxi">联系人关系</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="lianxirenguanxi" placeholder="请输入联系人关系"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="lianxirendianhua">联系人电话</label>
                        <div class="col-sm-6">
                            <input class="form-control" name="lianxirendianhua" placeholder="请输入联系人电话"/>
                        </div>
                    </div>


                    <!--	<div class="form-group row">
                            <label class="col-sm-4 col-form-label text-right" for="address">地址</label>
                            <div class="col-sm-6">
                                <input class="form-control"  name="address"  placeholder="请输入地址"/>
                            </div>
                        </div>-->
                    <div class="form-group row">
                        <label class="col-sm-4 col-form-label text-right" for="role">角色</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="role" placeholder="请输入角色">
                                <option value="">--请选择--</option>
                                <option value="2">检修领导</option>
                                <option value="5">总主任</option>
                                <option value="3">检修员</option>
                                <option value="4">司乘员</option>

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <!-- modal-body 结束 -->
            <div class="modal-footer">
                <button id="add_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.addForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="edit_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.editForm()">
                    <span class="glyphicon glyphicon-ok"></span>保存
                </button>
                <button id="delete_save_btn" type="button" class="btn btn-default btn-outline btn-sm"
                        onclick="operation.closeMoal()">
                    <span class="glyphicon glyphicon-remove"></span>关闭
                </button>
            </div>

        </div>
    </div>
</div>
<!-- 第一个model 结束 -->

<!-- Page-Level Scripts -->
<script type="text/javascript" th:inline="none">
    getZcxDepartmengList("departmentId")
    getZcxJobList("jobId")

    getZcxDepartmengList("departmentId2")
    getZcxJobList("jobId2")
    var operation = {
        searchForm: function () {
            $('#dg').bootstrapTable("refresh");
        },
        //弹出添加页面
        addWindow: function () {
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 1);

        },
        //添加表单
        addForm: function () {
            $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");


                $.post("/ZcxUser/insertZcxUser", temp, function (data) {

                    if (data.code != "3001") {
                        $("#dg").bootstrapTable("refresh");
                        $('#setFormId').data('bootstrapValidator').resetForm(true);
                        $('#setFormModal').modal('hide');
                    }

                    message.alert(data.showInfo);

                });
            }

        },
        //弹出修改页面
        editWindow: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            setForm("#setFormId", row);
            $('#setFormModal').modal('show');
            formObj.setBtnIsShow("add_save_btn", "edit_save_btn", 0);

        },
        //修改表单
        editForm: function () {
            var validate = $("#setFormId").bootstrapValidator('validate');
            if ($("#setFormId").data("bootstrapValidator").isValid()) {
                var temp = getFormJson("setFormId");
                $.post("/ZcxUser/updateZcxUser", temp, function (data) {

                    $("#dg").bootstrapTable("refresh");
                    message.alert(data.showInfo);
                    $('#setFormId').data('bootstrapValidator').resetForm(true);
                    $('#setFormId')[0].reset();
                    $('#setFormModal').modal('hide');
                });
            }

        },
        //删除表单
        deleteFrom: function (index) {
            var row = $("#dg").bootstrapTable("getData")[index];
            bootbox.confirm({
                size: "small",
                title: "提示",
                message: "确认删除这条数据吗？",
                callback: function (result) {
                    if (result) {
                        $.post("/ZcxUser/deleteZcxUser", {id: row.id}, function (data) {

                            $("#dg").bootstrapTable("refresh");
                            message.alert(data.showInfo);

                        });

                    }
                }
            });


        },
        //关闭页面
        closeMoal: function () {
            $('#setFormId').data('bootstrapValidator').resetForm(true);
            //$('#setFormId').reset();
            $('#setFormModal').modal('hide');
        },
        //导出
        exportFile: function () {


        },
        //审核
        audit: function () {


        },


    }


    $(function () {
        //表格格式化
        var fmt = {
            queryParams: function (params) {
                var temp = getFormJson("searchForm");
                temp.rows = params.limit;
                temp.currentPage = (params.offset / params.limit) + 1;
                return temp;

            },
            setTime: function (value, row, index) {

                return formatTimeYMDhms(value);  //转成年月日时分秒
            },
            setOpt: function (value, row, index) {
                var html = '';
                /* '<button class="btn-white btn btn-xs">查看</button>'+ */
                html += '<button id="edit_btn" class="btn btn-outline-secondary btn-sm"  onclick="operation.editWindow(' + index + ')">编辑</button>';
                html += '<button class="btn btn-outline-secondary btn-sm"  onclick="operation.deleteFrom(' + index + ')">删除</button>';
                return html;
            },
            setActImgUrl: function (value, row, index) {
                return '<img src="/TBook/queryPic?id=' + row.id + '" style="width:100px;heigth:100px"></img>';
            },


            setRole: function (value, row, index) {
                var htm = "";
                if (row.role == 1) {
                    htm = "系统管理员";
                }
                if (row.role == 2) {
                    htm = "检修领导";
                }
                if (row.role == 3) {
                    htm = "检修员";
                }
                if (row.role == 4) {
                    htm = "司乘员";
                }
                if (row.role == 5) {
                    htm = "总主任";
                }
                return htm;
            },
        }

        var columns = [[
            /*
             {
               field:'ck',
               width:'2%',
               checkbox:false,
               align:'center',

           },  */
            {
                field: 'id',
                title: 'id',
                width: 10,
                align: 'center',
                visible: false
            },

            {title: '账号', field: 'username', align: 'center', valign: 'middle', visible: true},
            {title: '密码', field: 'password', align: 'center', valign: 'middle', visible: true},
            {title: '姓名', field: 'name', align: 'center', valign: 'middle', visible: true},
            {title: '电话', field: 'phone', align: 'center', valign: 'middle', visible: true},


            {title: '邮箱', field: 'email', align: 'center', valign: 'middle', visible: true},
            {title: '岗位', field: 'jobName', align: 'center', valign: 'middle', visible: true},
            {title: '部门', field: 'departmentName', align: 'center', valign: 'middle', visible: true},
            /*
        {title: '紧急联系人', field: 'lianxirenxingming', align: 'center', valign: 'middle',visible:true},
        {title: '紧急联系人关系', field: 'lianxirenguanxi', align: 'center', valign: 'middle',visible:true},
        {title: '紧急联系人电话', field: 'lianxirendianhua', align: 'center', valign: 'middle',visible:true},
*/
            {title: '电话', field: 'phone', align: 'center', valign: 'middle', visible: true},

            // {title: '地址', field: 'address', align: 'center', valign: 'middle',visible:true},
            {title: '角色', field: 'role', align: 'center', valign: 'middle', visible: true, formatter: fmt.setRole},
            {title: '操作', field: 'opt', align: 'center', valign: 'middle', visible: true, formatter: fmt.setOpt},


        ]];


        $('#dg').bootstrapTable({
            url: "/ZcxUser/query",
            sidePagination: "server",
            queryParams: fmt.queryParams,
            method: "post",
            contentType: "application/x-www-form-urlencoded",
            pagination: true,
            pageNumber: 1,
            pageSize: 10,
            pageList: [10, 25, 50, 100],
            //search:true,
            clickToSelect: true,
            singleSelect: true,
            toolbar: '#toolbar',
            columns: columns,
        })

    });


    $(function () {
        $("#setFormId").bootstrapValidator({
            /* live:'disabled',
            excluded:[':disabled'],
            feedbackIcons: {
        　　　　　　　　valid: 'glyphicon glyphicon-ok',
        　　　　　　　　invalid: 'glyphicon glyphicon-remove',
        　　　　　　　　validating: 'glyphicon glyphicon-refresh'
    　　　　　   },*/
            fields: {


                username: {
                    validators: {
                        notEmpty: {
                            message: "用户名不能为空!",
                        },
                    }

                },


                password: {
                    validators: {
                        notEmpty: {
                            message: "密码不能为空!",
                        },
                    }

                },


                name: {
                    validators: {
                        notEmpty: {
                            message: "姓名不能为空!",
                        },
                    }

                },


                phone: {
                    validators: {
                        notEmpty: {
                            message: "电话不能为空!",
                        },
                    }

                },


                address: {
                    validators: {
                        notEmpty: {
                            message: "地址不能为空!",
                        },
                    }

                },


                role: {
                    validators: {
                        notEmpty: {
                            message: "角色不能为空!",
                        },
                    }

                },


            }

        });


    })


</script>

</body>

</html>
